#include "01_fs.h"

#if __cplusplus > 201703L && __has_include(<filesystem>)
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #include <boost/filesystem.hpp>
    namespace fs = boost::filesystem;
#endif

namespace lib_wrapper {
    bool exists(const std::string& path) {
        return fs::exists(path);
    }

    bool is_directory(const std::string& path) {
        return fs::is_directory(path);
    }

    bool create_directory(const std::string& path) {
        return fs::create_directory(path);
    }

    bool remove(const std::string& path) {
        return fs::remove(path);
    }

    std::string current_path() {
        return fs::current_path().string();
    }

    uintmax_t file_size(const std::string& path) {
        return fs::file_size(path);
    }

    bool copy_file(const std::string& from, const std::string& to) {
    #if __cplusplus > 201703L && __has_include(<filesystem>)
        return fs::copy_file(from, to, fs::copy_options::overwrite_existing);
    #else
        return fs::copy_file(from, to, fs::copy_options::overwrite_existing);
    #endif
    }

    std::string extension(const std::string& path) {
        return fs::path(path).extension().string();
    }

    bool create_directories(const std::string& path) {
        return fs::create_directories(path);
    }

    std::string parent_path(const std::string& path) {
        return fs::path(path).parent_path().string();
    }

    bool rename(const std::string& old_path, const std::string& new_path) {
        fs::rename(old_path, new_path);
        return true;
    }

    std::string preferred_separator() {
        return std::string(1, fs::path::preferred_separator);
    }

    std::string base_name(const std::string& path) {
        fs::path p(path);
        return p.stem().string();
    }

    std::string path_join(const std::string& path1, const std::string& path2) {
        fs::path p1(path1);
        fs::path p2(path2);
        return (p1 / p2).string();
    }
}
